const FileUpload = require('../../tools/FileUpload');
const Base=require('../base');
module.exports = class extends Base{
     /**
     * 上传一个文件公用接口
     * @returns {*}
     */
    uploddFileAction(){
        let upFileObj=this.ctx.file();
        let fileArr=[];
        for(let item in upFileObj){
            fileArr.push(upFileObj[item]);
        }
        if(fileArr.length<=0){
            this.ctx.fail(50002,'没有选择上传文件');
            return false;
        }
        if(fileArr.length>1){
            this.ctx.fail(50001, '只能上传一个文件');
            return false;
        }

        let fileObj = new FileUpload(fileArr[0], think.ROOT_PATH + '/www/uploads/imgs/');
        let fileInfo = fileObj.save();
        if (think.isEmpty(fileInfo))
        {
            this.ctx.fail(51001, '移动上传文件失败');
            return false;
        }else {
            this.ctx.fail(0, '文件上传成功',fileInfo);
            return false;
        }
    }
};